﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
///WebUserDAL 的摘要说明
/// </summary>
public class WebUserDAL
{
    /// <summary>
    /// 网站登陆
    /// </summary>
    /// <param name="userName">用户名</param>
    /// <param name="pwd">密码</param>
    /// <returns></returns>
    public bool Web_Login(string userName, string pwd)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("@userName", SqlDbType.VarChar, 20, userName);
            tool.AddSqlParameter("@pwd", SqlDbType.VarChar, 20, pwd);
            DataSet ds = Emoney.DataAccess.SqlHelper.ExecuteDataset(DBConn.Con_emweb_new, CommandType.StoredProcedure, "Web_Login", tool.GetSqlParameters());
            if (ds.Tables[0].Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "Web_Login", LogYuMin.LogStates.ERROR, ex);
            return false;
        }
    }

    /// <summary>
    /// 根据用户名得到用户的网上积分
    /// </summary>
    /// <param name="userName">用户名</param>
    /// <returns>积分列表</returns>
    public DataTable GetIntegralByUserName(string userName)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("@userName", SqlDbType.VarChar, 20, userName);
            DataSet ds = Emoney.DataAccess.SqlHelper.ExecuteDataset(DBConn.Con_emweb_new, CommandType.StoredProcedure, "GetIntegralByUserName", tool.GetSqlParameters());
            DataTable tb = ds.Tables[0];
            return tb;
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "GetIntegralByUserName", LogYuMin.LogStates.ERROR, ex);
            return null;
        }
    }

    /// <summary>
    /// 根据用户名得到积分明细
    /// </summary>
    /// <param name="userName">用户名</param>
    /// <returns>明细列表</returns>
    public DataTable GetIntegralDetailByUserName(string userName)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("@userName", SqlDbType.VarChar, 20, userName);
            DataSet ds = Emoney.DataAccess.SqlHelper.ExecuteDataset(DBConn.Con_emweb_new, CommandType.StoredProcedure, "GetIntegralDetailByUserName", tool.GetSqlParameters());
            DataTable tb = ds.Tables[0];
            return tb;
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "GetIntegralDetailByUserName", LogYuMin.LogStates.ERROR, ex);
            return null;
        }
    }

    /// <summary>
    /// 根据用户名得到用户信息
    /// </summary>
    /// <param name="userName">用户名</param>
    /// <returns>用户信息</returns>
    public DataRow GetWebUserByUserName(string userName)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("userName", SqlDbType.VarChar, 20, userName);
            DataSet ds = Emoney.DataAccess.SqlHelper.ExecuteDataset(DBConn.Con_emweb_new, CommandType.StoredProcedure, "GetWebUserByUserName", tool.GetSqlParameters());
            return ds.Tables[0].Rows[0];
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "GetWebUserByUserName", LogYuMin.LogStates.ERROR, ex);
            return null;
        }
    }
}